package com.hn.sanya.xintou;

import com.hn.sanya.demo.wx.server.MenuServer;
import com.hn.sanya.demo.wx.util.XmlToMapUtil;
import com.hn.sanya.demo.wx.util.GetToken;
import com.hn.sanya.demo.wx.vo.menu.*;
import com.hn.sanya.demo.wx.vo.message.Artics.Articles;
import com.hn.sanya.demo.wx.vo.message.Artics.ArticlesMessage;
import net.sf.json.JSONObject;
import org.junit.Test;
import org.weixin4j.WeixinException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述: 测试类
 * @param:
 * @return:
 * @auther: lxh
 * @date: 2019/1/30
 */
public class test {

    //Articles封装测试
    @Test
    public void Test(){
        Articles articles=new Articles();
        articles.setUrl("http://www.baidu.com");
        articles.setTitle("收集卡卷有机会获得五福哦");
        articles.setDescription("分享给好友即可获得卡卷");
        articles.setPicUrl("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1224624780,2214207906&fm=27&gp=0.jpg");

        Map<String, String> requestMap =new HashMap<>();

        requestMap.put("FromUserName","FromUserName");
        requestMap.put("ToUserName","ToUserName");
        requestMap.put("CreateTime","CreateTime");

        List<Articles> articlesList=new ArrayList<>();
        articlesList.add(articles);

        ArticlesMessage articlesMessage=new ArticlesMessage(requestMap,articlesList);

        String s= XmlToMapUtil.MapToXml(articlesMessage);

        System.out.println(s);

    }
    //获取token测试
    @Test
    public void getToken(){
        String token=null;
        try {
             token= GetToken.getToken();
        } catch (WeixinException e) {
            e.printStackTrace();
        }
        System.out.println(token);
    }
    //获取token测试
    @Test
    public void menu(){


        Button button=new Button();
        //第一个一级菜单
        button.getButton().add(new ClickButon("一级点击","1"));
        //第二个一级菜单
        button.getButton().add(new ViewButon("一级跳转","http://www.baidu.com"));
        //第三个一级菜单
        SubButon subButon=new SubButon("有子菜单");
        subButon.getSub_button().add(new PicSysphotoButon("发图","31"));
        subButon.getSub_button().add(new PicPhotoOrAlbumButon("拍照/相册","32"));
        subButon.getSub_button().add(new ScancodePushButon("扫码带提示","33"));
        subButon.getSub_button().add(new ScancodeWaitmsgButon("扫码推事件","34"));

        button.getButton().add(subButon);

        JSONObject data=JSONObject.fromObject(button);

        System.out.println(data);

        try {
            MenuServer.CreateMenu();
        } catch (WeixinException e) {
            e.printStackTrace();
        }


    }

}
